﻿using B.S.DataBase.MyProject.Domain.wdx;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure;
using MediatR;
using MedicalPCTerminal.Read.API.Appcation.Commands.Sign;

namespace MedicalPCTerminal.Read.API.Appcation.CommandHandlers.Sign
{
    public class GetSignDeviceBindCommandHandler:IRequestHandler<GetSignDeviceBindCommand, APIResult<List<SignDeviceBind>>>
    {
        private readonly SqlSugarContext sqlSugar;

        public GetSignDeviceBindCommandHandler(SqlSugarContext sqlSugar)
        {
            this.sqlSugar = sqlSugar;
        }

        public Task<APIResult<List<SignDeviceBind>>> Handle(GetSignDeviceBindCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<SignDeviceBind>> result = new APIResult<List<SignDeviceBind>>();
            result.data = sqlSugar.db.Queryable<SignDeviceBind>().Where(x => x.Patient_Id == request.ResidentFiles_Id).ToList();
            if (result.data.Count > 0)
            {
                result.Code = APIEnum.查询成功;
                result.Msg = APIEnum.查询成功.ToString();
            }
            else
            {
                result.Code = APIEnum.查询失败;
                result.Msg = APIEnum.查询失败.ToString();
            }
            return Task.FromResult(result);
        }
    }
}
